In: Computer Science
Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending in 3. • Write a for loop to display a string entered by the user backwards.
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Question 1 :
Here a new java with name "main.java" is created, which contains following code.
main.java :
/*Java program to find numbers between 13-93 that ends with
3*/
//Class Main
public class Main
{
//main method
public static void main(String[] args) {
//declaring variable
int i;
for (i=13;i<=93;i++)
{
//checking if number is end with 3
if(Integer.toString(i).endsWith("3")){
//display number
System.out.print(i+" ");
}
}
}
}
======================================================
Output : Compile and Run main.java to get the screen as shown below
Screen 1 :main.java
*********************************
Question 2 :
main.c :
/*Write a for loop to display a string entered by the user
backwards.*/
import java.util.*;
//Class Main
public class Main
{
//main method
public static void main(String[] args) {
//creating object of scanner class
Scanner scanner=new Scanner(System.in);
//asking user to enter string
System.out.println("Enter a string : ");
//reading string
String inputString=scanner.nextLine();
//converting string to character array
char[] strChar = inputString.toCharArray();
//finding length of string
int strLength=strChar.length;
//using for loop to print string backwords
for(int i=strLength-1;i>=0;i--)
{
//display string in backwords
System.out.print(strChar[i]);
}
}
}
================================
Output :Compile and run above program to get the screen as shown below
Screen 1:Screen asking to enter string
Screen 2 :Screen showing string backwords
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.