doubt in java

hiiiiiiii
can any one tell me what condition we should give in if statement in order to execute both if and else statements??
for ex:
if( ???)
System.out.println("hello");
else
System.out.println("world");

it should print helloworld,,please fill ????

problem m facing is in ?? i provide int it doesnot accept...and ! condiiton is giving error if i use System.out.println() function,s return value...
pls solve it......

Replies

  • silverscorpion
    silverscorpion
    Well, I don't get your question.
    The point of using if is to do one job or the other based on some condition.
    If you want to do both the jobs, then you dont need to use if itself.

    Perhaps if you provide some sample code and say where you face problems, we can be able to help..
  • Manish Goyal
    Manish Goyal
    It is not possible
    at least for me don't know about james 😀
  • Morningdot Hablu
    Morningdot Hablu
    ya goyal is right.
    but if it is a tricky question(we have to solve it by anyway).
    then i think that this is the method by which we have to do this.
    import java.io.*;
    class m
    {
    public static void main(String arg[])
    {
    boolean x;
    if(x=true)
    {
    System.out.println("mohit ");
    x=false;
    continue;
    }
    else
    {
    System.out.println("cboy hack the world");
    }
    }
    }
    but here what keyword is placed in the place of continue so that it will execute the if statement again.
  • optimystix
    optimystix
    silverscorpion
    Well, I don't get your question.
    The point of using if is to do one job or the other based on some condition.
    If you want to do both the jobs, then you dont need to use if itself.

    Perhaps if you provide some sample code and say where you face problems, we can be able to help..
    exactly!
    there's no point using an IF ELSE statement if both have to be typed. Even if it is a trick question, it is a foolish one 'cos one will never need an IF ELSE statement if both the things have to be worked out.
  • HImanshu_Sharma
    HImanshu_Sharma
    neha1
    hiiiiiiii
    can any one tell me what condition we should give in if statement in order to execute both if and else statements??
    for ex:
    if( ???)
    System.out.println("hello");
    else
    System.out.println("world");

    it should print helloworld,,please fill ????

    problem m facing is in ?? i provide int it doesnot accept...and ! condiiton is giving error if i use System.out.println() function,s return value...
    pls solve it......
    public class demoif {

    public static void main(String[] args) throws Exception {
    if ( System.out.printf("Hello") == null ) {

    }
    else {
    System.out.println("World");
    }
    }
    }
    it is the perfect ans u can try
  • bharathkumarp
    bharathkumarp
    Hey neha,if you want get the output as hello world, then try without else,then you definitely going to get the out put..But you can't get the both if and else part...
    other wise if you want to get those output fallow this code(using labels)...
    int a=1;
    l1:if(a==1)
    {
    System.out.println("hello");
    a=0;
    }
    else
    System.out.println("world");
    goto l1;

    this is work in c and c++,, But i'm not sure in java.. Just try...
  • silverscorpion
    silverscorpion
    bharathkumarp
    Hey neha,if you want get the output as hello world, then try without else,then you definitely going to get the out put..But you can't get the both if and else part...
    other wise if you want to get those output fallow this code(using labels)...
    int a=1;
    l1:if(a==1)
    {
    System.out.println("hello");
    a=0;
    }
    else
    System.out.println("world");
    goto l1;

    this is work in c and c++,, But i'm not sure in java.. Just try...
    Hey, this is an infinite loop man.. It'll go on printing

    helloworldworldworldworld....
  • AGRU
    AGRU
    yup , silverscorpion is right it goes fr infinite loop.

    i believe that we use " if else "only in case we want to solve cases of either or still if u solely aim only to print " hello world "
    then try like

    import java.io.*;
    class trial
    {
    public static void main(String args[])
    {
    boolean x;
    int c=0;
    while (c<2)
    {
    if(x=true)
    {
    System.out.println("hello" );
    x=false;
    }
    else
    System.out.println("world" );
    c=c + 1;
    }
    }
    but its like getting something purposefully.
    help me if i m wrong.
  • bharathkumarp
    bharathkumarp
    hi #-Link-Snipped-#, ya i am wrong.. But i can modify that code as fallow, If there is mistake please inform me and let me know how can write....

    int a=1,b=0;
    l1:if(a==1)
    {
    System.out.println("hello");
    a=0;
    }
    else
    System.out.println("world");
    if(b==0)
    {
    b=1;
    goto l1;
    }

You are reading an archived discussion.

Related Posts

My Native place is a city in Rajasthan (India), which is famous for desserts and hot summer seasons. One day I was wondering that there are tons of sand dunes...
With Steve Jobs publicly writing that Adobe's Flash software has technical faults that has resulted into Apple's decision of banning Flash on iPhone & iPad platforms; I think it would...
Can suggest an IT company in Coimbatore or Ooty , TN for an industrial visit of students from B.Tech(IT)....If you know suggest us...Am badly needing it.../😒...All your ideas are welcomed.,.
hi can anyone tell me project ideas on design or product related projects like consumer products,etc
can anyone tel me how to prepare for Bel probationary exam 2010 and which books to read