Padding Will NOT Work - Adding Spaces?
Apr 22, 2014
Why this will not pad?? It keeps displaying normally, even if i add spaces it will not work.
System.out.printf("%-20s%-20s%-20s%-20s", p.getLastName(),
p.getLastName(), p.getSocialSecurityNumber(),p.getAge());
This is what it is printing:
=================== =================== ====================== ===
lastname, firstname, 123-12-1234, 16
The lastname, firstname, 123-12-1234, 16 should be padded and appear with about 20 spaces between them.
View Replies
ADVERTISEMENT
Jul 27, 2014
What I am doing is loading a new image from resources in my project, so that I can get the size. Using this, I create a new BufferedImage with those dimensions. The following code is what I am using to take the original BufferedImage, and scale it.
Java Code:
public ImageIcon getBackImage(){
before = new BufferedImage((int)img.getWidth(null), (int)img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
int w = before.getWidth();
int h = before.getHeight();
try{
URL url = getClass().getResource("/Blue_Back.png");
before = ImageIO.read(url);
[Code] ......
The scaling seems to be working fine, but what I have noticed is a line of approximately 10 pixels at the top of the image. I took the original image and blew it up to ensure that I wasn't just enlarging undesired portions and this wasn't the case. I then tried to fetch a subImage of the BufferedImage, and that also left the padding at the top. Is there something I am missing that is placing this undesired padding at the top of my bufferedImages ?
View Replies
View Related
Apr 22, 2015
I'm trying to establish an SSL connection (using a self-signed certificate). However, I can't seem to get the handshake to work. At the moment server side, I've created the public/private key + signed certificate and then stored them in a KeyStore. I've also stored this signed certificate in a KeyStore (trustStore) client side, so it can compare.
Keys: RSA, Certificate Sig: SHA256withRSA, cipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA
Client Code
// 34393570706261
SSLContext context = SSLContext.getInstance("TLS");
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(client_trustStore);
context.init(null, tmf.getTrustManagers(), new SecureRandom());
SSLSocketFactory socketFactory = context.getSocketFactory();
conn = (SSLSocket) socketFactory.createSocket("localhost", port);
String[] suites = new String[]{"TLS_RSA_WITH_AES_128_CBC_SHA"};
conn.setEnabledCipherSuites(suites);
[Code] ....
Errors
Quote
javax.net.ssl.SSLHandshakeException: Invalid Padding length: (number)
WARNING: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
WARNING: javax.net.ssl.SSLException: Connection has been shutdown:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
View Replies
View Related
Apr 21, 2015
I have created this program that outputs
1
12
123
1234
12345
123456
I tried looking up some ways to create spaces in between each number, but I failed miserably. Here is what I have right now.
public class Iterations {
public static void main(String[] args){
for(int i=1;i<=6;i++)
{
for(int j=1;j<=i;j++)
System.out.print(j);
[Code] ....
View Replies
View Related
May 2, 2014
I do not know how to read a name which has spaces in Java and I wish to learn. The following is my code
import java.util.*;
public class Asking {
public static void main(String []args) {
Scanner reader = new Scanner(System.in);
String [] names = new String[20];
int [] marks = new int[20];
[code]....
View Replies
View Related
Oct 14, 2014
I am having a problem of how to write a program dat will input one number consisting of five digit,separate the number and print the digits separated from one another by three spaces each.. I tried to use divisional and remainder operation but it didn't work.
View Replies
View Related
Feb 4, 2014
How can i make sure that when user enter value there is no space between words example :
NEW YORK MUST BE NEW YORK
View Replies
View Related
Jan 21, 2014
I am trying to split a string into a String[] tokens array to declare variables for an object; however, I'm having an issue getting the string to tokenize correctly. Here's an example of the input:
a : 100 : John Smith : 20 Main St.
a : 101 : Mary Jones : 32 Brook Rd.
Here is the basic code I have now, to properly sort each line of text, etc. (without the split() method):
Java Code:
while (scanner.hasNextLine()) {
currentLine = scanner.nextLine();
lineScan = new Scanner(currentLine);
if (currentLine.startsWith("/") || currentLine.trim().isEmpty())
continue;
[Code] ....
I was able to eliminate the comments and identifiers from the text by trimming the first two characters of the string. For the split, I tried String[] tempArray = currentLine.split("s+"); however, that also took the spaces out of the addresses and names...so the results looked like this:
100
John
Smith
20
Main
St.
As you can see, it splits via space regardless, including where I replaced all the :'s with spaces. Is there any way to do this?
View Replies
View Related
Apr 6, 2014
I'm not sure why but my infix string isn't removing the spaces. Here is the part of the code:
Scanner s = new Scanner(System.in);
System.out.println("Enter Infix express: ");
String infix = s.nextLine();
infix.replaceAll("\s", "").trim();
System.out.println(infix);
InfixtoPostfix convert = new InfixtoPostfix(infix);
String postfix = convert.toPostFix();
System.out.println("Converted Express: " + postfix);
Is there something I'm doing wrong? Here is the output when I run it:
Enter Infix expression:
(7 + x) * (8 – 2) / 4 + (x + 2)
(7 + x) * (8 – 2) / 4 + (x + 2)
Converted Expression: 7 x+ 8 – 2* /4 x 2++
View Replies
View Related
Mar 1, 2014
My method below works fine to print a matrix but when it prints every row, it is printing extra 4 white spaces which is not required. How can I delete those extra spaces at the end? when I use
System.out.print((matrix[i][j] + " ").replaceAll("^s+", ""));
It trims every thing including the spaces I needed for my matrix. So where should I put replaceAll("^s+", "") ?
Java Code:
private static void printMatrix(int[][] matrix) {
System.out.println();
System.out.println("Matrix:");
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
} mh_sh_highlight_all('java');
View Replies
View Related
Oct 5, 2014
I am working on a small brain teaser project where I am taking a string input from a Scanner, and turning into ascii. The problem comes into play when the string has a space in it, so if the question is what's your name? and you say Michael Jackson, Michael gets converted then Jackson becomes the answer to the next question, rather then the second portion of the current string.
This is an older version of what I'm doing currently, but it had the same basic problem with spaces.I will say I did my current version entirely different.
nner user_input = new Scanner (System.in);
//Creates a string
String favoriteFlick;
System.out.println("Enter the title of your favorite film?");
favoriteFlick = user_input.next();
[Code] .....
View Replies
View Related
Mar 1, 2014
My method below works fine to print a matrix but when it prints every row, it is printing extra 4 white spaces which is not required. How can I delete those extra spaces at the end? when I use
System.out.print((matrix[i][j] + " ").replaceAll("^s+", ""));
It trims every thing including the spaces I needed for my matrix. So where should I put replaceAll("^s+", "") ?
private static void printMatrix(int[][] matrix) {
System.out.println();
System.out.println("Matrix:");
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}
View Replies
View Related
Feb 7, 2014
I create a Audit file within my Java program, which gets all the System.out.println lines from the code.
For example, the System.out.println lines in my code are as follows:-
Records initially inserted into edited: 70144
Bad license number records removed: 5
Total records in edited: 70139
Records initially inserted into tabedited:7463
I want all my values aligned after the statement, when they are printed to the Audit File.
Instead of just giving spaces by counting the number of charaters in the line, is there any other way to align them.
View Replies
View Related
Nov 7, 2014
public class ArrayPrinter {
public static void main(String[] args) {
int[] oneD = {5, 6, 7, 8};
PrintArray(oneD);
}
public static void PrintArray(int[] Arr) {
System.out.println ('[');
for (int i =0; i >= Arr.length; i++) {
System.out.print (Arr[i]);
if (i < Arr.length){
System.out.print(", ");
}
System.out.print (']');
}
}
}
I tried to format this to enhance readability but I'm not sure if I managed to improve it any... This code should be printing the contents of the array with spaces and commas its just printing [. I think this is because Arr is empty for some reason but I'm not sure why it would be when it gets the values of oneD passed to it.
View Replies
View Related
Nov 28, 2014
I am trying to make a java code that reads in lines of text and returns the number of spaces in each line.I think i have made it but i can not compile it..
Here is my code:
class Mainh {
public static void main( String args[] ) {
System.out.print( "#Enter text : " );
String text = BIO.getString();
while ( ! text.equals( "END" ) )
[Code] ....
View Replies
View Related
Jan 17, 2015
I am creating a calculator in which a user will directly input the numbers and the operator...
Here is my code:
int answer = 0;
int num1, num2;
char operator;
System.out.print("Enter calculation: ");
num1 = kb.nextInt();
operator = kb.next().charAt(0);
num2 = kb.nextInt();
The code above will accept the user input when there are spaces like this: 1 + 1
So the program will give an answer which is 2...BUT
if i input 1+1 it will give an error...Exception in thread "main" java.util.InputMismatchException
How can i do that it will separate integer to character? because i set the operator as character....
So that it will accept one digit to several digit numbers... like 500+84 or 1520+872??
View Replies
View Related
Apr 9, 2015
I created a simple Hangman game. It functions correctly, the only issue is when the file contains a phrase (2 or more words), spaces are not displayed when the program is run. For example, if the phrase was Java Programming Forums.
It would appear as _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
I want there to be spaces in between the words. How could I fix this? What would I need to add to my code?
import java.util.Scanner;
import java.io.*;
public class hangman{
public static void main (String[] args) throws FileNotFoundException{
Scanner kb = new Scanner(System.in);
String guess;
String guesses = "";
int wrongGuess = 8;
[Code] ....
View Replies
View Related
Mar 11, 2014
Write an application that inputs one number consisting of five digits from the user, separates the number into in individual digits and prints the digits separated from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each.
For example, if the user types in the number 42339,
the program should input 4 2 3 3 9.
Here is my code so far but I am stuck.
mport java.util.Scanner;
public class Seperating {
public static void main ( String[] args) {
Scanner input = new Scanner(System.in);
int number = 0 ;
System.out.printf("%d" , number );
System.out.print("Enter integer");
number = input.nextInt();
}
}
but I am not getting the result I wanted what am I doing wrong
View Replies
View Related
Sep 18, 2014
double a = scan.nextInt();
double b = scan.nextInt();
double c = scan.nextInt();
//**********************************Equations**********************************
System.out.println ();
double sum = a + b + c;
System.out.printf("Sum = %d", sum);
Heres the error I'm getting
Enter three positive integers separated by spaces, then press enter:
15 20 9
Sum = Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at project2.main(project2.java:52)
View Replies
View Related
Apr 5, 2014
I am trying to write a program and the name variable can only store letters,dotes and spaces. But whenever I enter a space, the program doesn't work. Following is my code.
import java.util.Scanner;
import java.util.*;
public class Space {
public static void main(String []args) {
Scanner reader = new Scanner(System.in);
[Code] ....
View Replies
View Related
Oct 6, 2014
In Oracle SQL, when you do trim(column_name), if column_name is blank spaces only (say datatype is CHAR(8)), then "trim(column_name) is null" is true.
In JPQL, if you do "TRIM ( BOTH FROM p.column_name ) is null", does it evaluate to true just like in Oracle SQL?
The reason I'm asking, is my colleague wrote some code in JPQL like below:
... TRIM ( BOTH FROM CONCAT(p.column_name, '#@') ) = '#@'
He said he originally wanted to compare the TRIM result to empty String '', but the result is false, so he concat the column to some junk.
So if after the TRIM, the result is the same junk he added, then the column contains only blanks. I think this works but there could a simpler way to do it.
View Replies
View Related
Jun 18, 2014
The problem is as follows: I've been running java script using git bash and at one point it tells me that I need to increase heap size because apparently it takes more than 1gb to run. However although I manually increase it via control panel>programs>java nothing changes. I've been told that I need to ' figure out how to use 64bit java (and a VM that supports 64bit) in order to increase the maximum memory allocation (heap size) to something north of 2g.'
My laptop has 8GB worth of RAM (Windows 7)so it shouldn't technically have problems running anything above 1G. But there is apparently a 1GB wall But increasing the heap size to above 2G results in an error stating that VM doesn't initialize within git bash, I thought that my java is 32 bit so I downloaded a 64 bit java. Now how and if it is even possible to allocate a program to run under 64 bit java and if I should delete the other java version.
View Replies
View Related
Dec 13, 2014
how does recursion works, I don't understand why it prints al numbers going up again?This is the code
void print2(int n){
if (n<0){
out.printf(" %d",-1);
return;
}
out.printf(" %d", n);
print2(n-1)
out.printf(" %d", n);
}
this should be the output if n is 6: 6 5 4 3 2 1 0 -1 0 1 2 3 4 5 6.
View Replies
View Related
Mar 6, 2015
I need to create a chart for work and comes across this sample from mbostock's chord diagram (bl.ocks.org/mbostock/4062006).
I only need to revise the tick label (names, display positions) but I don't know how to do it as I have 0 experience with Java.
My sample data for the var matrix is
[0,100,100,100]
[0,0,99,98]
[0,0,92,84]
[0,99,0,0]
which shows flows between country A, B, C and D.
I would like to revise the tick labels, so that:
1) Instead of showing 0K 5K 10K, I would like to show the country names (A - D), with no number or tick. I figured out this one by just commenting out all the codes relating to ticks.
2) Place the country names in the center of the arch. I don't know how to do this one.
View Replies
View Related
Mar 5, 2014
a buffer reader , how does it work and what is the code for it ?
View Replies
View Related
Oct 9, 2014
I've got a panel which an arbitrary number of text fields may be added to at run time. I've got it set up so that the window's height, and the height of the panel in which the fields appear will never exceed the height of the screen.What I don't have is a way to make the panel scroll to access the fields that are being visually truncated. I'm setting the autoscrolls on the panel to true, but when I run the program, the fields are simply truncated.
pnlDeclensions.setAutoscrolls(true);
View Replies
View Related