0% found this document useful (0 votes)
9 views5 pages

M Shoaib#80

The document contains code snippets from multiple Java programming exercises. It includes examples of string methods like substring, indexOf, and replace. It also shows how to read input from files and perform basic calculations and output formatting.

Uploaded by

Shoaib Kareem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

M Shoaib#80

The document contains code snippets from multiple Java programming exercises. It includes examples of string methods like substring, indexOf, and replace. It also shows how to read input from files and perform basic calculations and output formatting.

Uploaded by

Shoaib Kareem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Muhammad Shoaib

Roll No# 02080

Exercise Q.9
public class Exercise9 {
public static void main(String [] args) {
String str="Going to the amusement park";
System.out.println(str.substring(0, 5));
System.out.println(str.substring(13, 22));
System.out.println(str.toUpperCase());
System.out.println(str.toLowerCase());
System.out.println(str.replace('t', '*'));
}

}
Output

Exercise Q.10

public class Exercise10 {


public static void main(String[] args) {
String str= "Java programming: from problem analysis to program
design";
System.out.println(str.indexOf("analysis"));
System.out.println(str.substring(5, 16));
System.out.println(str.startsWith("Java"));
System.out.println(str.startsWith("J"));
System.out.println(str.endsWith("."));
}

Output
Exercise Q.17
import javax.swing.JOptionPane; public
class Exercise17 { public static void
main(String[] args) {
JOptionPane.showMessageDialog(null,"Current tempreture:70
degree","Greetings",JOptionPane.QUESTION_MESSAGE);
}
}

Output

Exercise Q.20

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.*;
public class Exercise20
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner inFile =
new Scanner(new FileReader("Ex20Input.txt"));
int num1, num2;
num1 = inFile.nextInt();
num2 = inFile.nextInt();
System.out.println("Sum = " + (num1 + num2));
inFile.close();
}
}
Output

ProgrammingExercise 4
package programmingExercise4; import java.util.*;
public class programmingExercise4{ static Scanner
console = new Scanner(System.in); public static
void main(String[] args)
{ double cost;
double area;
double bagSize;
System.out.print("Enter the amount of fertilizer, "
+ "in pounds, in one bag: "); bagSize
= console.nextDouble();
System.out.println();
System.out.print("Enter the cost of the " + bagSize
+ " pound fertilizer bag: "); cost
= console.nextDouble();
System.out.println();
System.out.print("Enter the area, in square feet, that "
+ "can be fertilized by one bag: "); area
= console.nextDouble();
System.out.println();
System.out.printf("The cost of the fertilizer per pound is: "
+ "$%.2f%n", bagSize / cost);
System.out.printf("The cost of fertilizing per square "
+ "foot is: $%.4f%n", area / cost);
}
}

Output

You might also like