Showing posts with label print. Show all posts
Showing posts with label print. Show all posts

Friday, 6 December 2019

What will the following code fragment printout?

What will the following code fragment printout? 
String myString = "Java": System.out.println(myString.toUppercase() + "or" + myString): 
 A. java or Java 
B. Java or Java 
C. JAVA or JAVA 
D. JAVA or Java

Solution:

 
D (JAVA or Java)

The below program has two varints the first variant which converts all characters in the string to upper case and second variant takes locale as argument and converts into upper case

Write a complete Java program for the following questions

Q. Write a complete Java program for the following questions:    
         Write a program that print the following on the screen.
Java
Java Java
Java Java Java
Java Java Java Java
Java Java Java Java Java

Solution:

 
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       int i,j;
       for(i=0;i<5;i++)
       {
           for(j=0;j<=i;j++)
               System.out.print("JAVA ");
             
           System.out.println();
       }
   }
}